package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.common.helper.HttpRequestHelper;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.common.util.MD5;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author study
 * @version 1.0
 * @date 2021/5/7 16:34
 */
@RestController
@RequestMapping("/api/host")
public class ApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private HospitalSetService hospitalSetService;

    //上传医院接口
    @PostMapping("saveHospital")
    public Result saveHosp(HttpServletRequest request) {

        final Map<String, String[]> requestMap = request.getParameterMap();
        final Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(requestMap);
        final String sign = (String) stringObjectMap.get("sign");

        //根据传递过来的医院编号，查询数据签名
        final String hoscode = (String) stringObjectMap.get("hoscode");
        String sginKey = hospitalSetService.getSignKey(hoscode);
        final String signKeyMd5 = MD5.encrypt(sginKey);

        hospitalService.save(stringObjectMap);
        return Result.ok();
    }

}
